package ZoneId_Demo;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class demo3 {
    public static void main(String[] args) {
        //获取现在时间和时区
        ZonedDateTime now = ZonedDateTime.now();
        System.out.println(now);
        //获取指定的时间对象
        ZonedDateTime time1 = ZonedDateTime.of(2023,10,1,11,12,12,0,ZoneId.of("Asia/Shanghai"));
        System.out.println(time1);
        Instant instant = Instant.ofEpochMilli(0L);
        ZoneId zoneId = ZoneId.of("Asia/Shanghai");
        ZonedDateTime time2 = ZonedDateTime.ofInstant(instant,zoneId);
        System.out.println(time2);

        //withXXX 修改时间系列的方法
        ZonedDateTime time3 = time2.withYear(2000);
        System.out.println(time3);

        //minusXXX减少时间
        ZonedDateTime time4 = time3.minusYears(10);
        System.out.println(time4);

        //plusXXX增加时间

        ZonedDateTime time5 = time4.plusYears(10);
        System.out.println(time5);
    }
}
